<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        body {
            background-color: aliceblue;
        }

        .poemBox {
            display: flex;
        }

        .item {
            width: 300px;
            min-height: 200px;
            background-color: antiquewhite;
            border: 1px solid #f60;
            text-align: center;
            margin: 20px;

        }

        .author {
            font-size: 12px;
            color: gray;
        }

        button {
            margin-left: 20px;
        }
    </style>
</head>

<body>
    <button class="back">后退</button>
    <div class="poemBox">
        <!-- <div class="item">
            <h3>静夜思</h3>
            <p class="author">作者:李白</p>
            <p><span>床前明月光,</span><span>疑是地上霜。</span></p>
            <p><span>举头望明月,</span><span>低头思故乡。</span></p>
        </div> -->
    </div>
    <script>
        // 获取本地数据
        let poems = JSON.parse(localStorage.getItem('poems'))

        //渲染数据
        let add = poems.map(function(item,index){
            item.contents = item.contents.split(',')
            let tx = ''
            for (let i = 0; i < item.contents.length; i++) {
                if ((i + 1) % 2 === 0) {
                    tx +=`
                    <p><span>${item.contents[i - 1]},</span><span>${item.contents[i]}.</span></p>
                    `
                }
            }
            return `
        <div class="item">
            <h3>${item.title}</h3>
            <p class="author">作者:${item.author}</p>
            ${tx}
        </div>
            `
        })
        document.querySelector('.poemBox').innerHTML = add.join('')
        
    </script>
</body>

</html>